<template>

    

  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
         
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
         
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          
        >导出</el-button>
      </el-col>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>


    <el-table  :data="list">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="fileId" />
      <el-table-column label="患者姓名" align="center" prop="patientId" />
      <el-table-column label="左耳听力" align="center" prop="leftEarHearing" />
      <el-table-column label="右耳听力" align="center" prop="rightEarHearing" />
      <el-table-column label="左眼视力" align="center" prop="leftVision" />
      <el-table-column label="右眼视力" align="center" prop="rightVision" />
      <el-table-column label="修改时间" align="center" prop="updateTime" />
      <el-table-column label="身高" align="center" prop="height" />
      <el-table-column label="体重" align="center" prop="weight" />
      <el-table-column label="血型" align="center" prop="bloodType" />
      <el-table-column label="个人史" align="center" prop="personalInfo" />
       <el-table-column label="紧急联系人" align="center" prop="emergencyContactName" />
      <el-table-column label="紧急联系人电话" align="center" prop="emergencyContactMobile" />
    <!-- <el-table-column>
      <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          
          @click="handleUpdate(row)"
        
        >修改</el-button></el-table-column> -->

        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
           
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total=total>
    </el-pagination>

    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="患者编号" prop="fileId">
          <el-input v-model="form.fileId" placeholder="请输入患者编号" />
        </el-form-item>
        <el-form-item label="患者ID" prop="patientId">
          <el-input v-model="form.patientId" placeholder="请输入患者id" />
        </el-form-item>
        <!-- <el-form-item label="日期" prop="date">
          <el-date-picker clearable size="small"
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="紧急联系人" prop="emergencyContactName">
          <el-input v-model="form.emergencyContactName" type="textarea" placeholder="请输入紧急联系人" />
        </el-form-item>
        <el-form-item label="紧急联系人电话" prop="emergencyContactMobile">
          <el-input v-model="form.emergencyContactMobile" placeholder="请输入紧急联系人电话" />
        </el-form-item>
        <el-form-item label="紧急联系人关系" prop="flowId">
          <el-input v-model="form.emergencyContactRelation" placeholder="紧急联系人关系" />
        </el-form-item>
         <el-form-item label="左耳听力" prop="leftEarHearing">
          <el-input v-model="form.leftEarHearing" placeholder="请输入左耳听力" />
        </el-form-item>
         <el-form-item label="右耳听力" prop="rightEarHearing">
          <el-input v-model="form.rightEarHearing" placeholder="请输入右耳听力" />
        </el-form-item>"
         <el-form-item label="左眼视力" prop="leftVision">
          <el-input v-model="form.leftVision" placeholder="请输入左眼视力" />
        </el-form-item>
         <el-form-item label="右眼视力" prop="rightVision">
          <el-input v-model="form.rightVision" placeholder="请输入右眼视力" />
        </el-form-item>
         <el-form-item label="体重" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入体重" />
        </el-form-item>
         <el-form-item label="身高" prop="height">
          <el-input v-model="form.height" placeholder="请输入身高" />
        </el-form-item>
         <el-form-item label="个人史" prop="personalInfo">
          <el-input v-model="form.personalInfo" placeholder="请输入个人史" />
        </el-form-item>
         <el-form-item label="家族史" prop="familyInfo">
          <el-input v-model="form.familyInfo" placeholder="请输入家族史" />
        </el-form-item>

        
        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
   
  </div>
</template>

<script>
import { getList,add,getByid,deleteFile,updateFile } from "@/api/patient/patientfile";

export default {
  // doctor  医生  
  name: "doctor",
  data() {
    return{
        // 分页后的当前页数据
        list: [],
        //当前数据页的第几页
        currentPage: 1,
        // 总数据条数xx
        total: 0,
        // 每页显示多少行数据,默认为10条
        pagesize: 10,
        // 代表是从后端获取的所有数据
        ticket: [],
        //对话框是否显示
        open:false,
        form:"",
        title: "",
        single: true,
        multiple:true,
           // 遮罩层
        loading: true,
       // 导出遮罩层
        exportLoading: false,
        // 表单参数
         form: {},
      // 表单校验
          rules: {
      },
      // 显示搜索条件
      showSearch: true,

    }   
  },
  created() {
        this.getPatientFile();
  },
  methods: {
     // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        
      };
      // this.resetForm("form");
    },
     /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const id = row.id || this.ids
    //   getCompare(id).then(response => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改招标报价对比";
    //   });
    // },
    /** 查询患者表数据 */
    getPatientFile() {
          //this.listLoading = true;
         getList().then(response => {
            console.log(response.data[0]+"患者数据");
            if(response.code === 200){
                this.ticket = response.data;
                //获取返回数据的总行数
                this.total = response.data.length;
                // 获取当前页的数据,此方法在下方定义
                this.getDoctorInfo()
                this.$message({
                    message: '数据加载成功',
                    type: 'success'
                })
            } else {
                // 失败提示信息
                this.$$message({
                    message: '数据加载错误',
                    type: 'error'
                })
            }
         });
    },
    // 此方法用来获取当前页的数据
    getDoctorInfo(){
        // 清空表格的list 数据
        this.list=[];
        // 获取当前页的数据
        for(
            let i = (this.currentPage - 1) * this.pagesize;
            i < this.total;
            i++
        ){
            // 将便利的数据添加到 list 里面
            this.list.push(this.ticket[i]);
            // 判断是否达到每一页的要求
            if(this.list.length === this.pagesize)
            break;
        }
    },
    // 分页时修改每页的行数,这里会自动传入一个size
    handleSizeChange(size) {
        // 修改当前每页的数据行数
        this.pagesize = size;
        // 数据重新分页
        this.getDoctorInfo();
    },
    // 调整当前的页码
      handleCurrentChange(pageNumber) {
          // 修改当前的页码
        this.currentPage = pageNumber;
        //数据重新分页
        this.getDoctorInfo();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加劳务付款";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.fileId || this.fileId
      getByid(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改患者信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fileId != null) {
            updateFile(this.form).then(response => {
              // this.$modal.msgSuccess("修改成功");
              this.$message({
                    message: '数据修改成功',
                    type: 'success'
                })
              this.open = false;
              this.getList();
            });
          } else {
            add(this.form).then(response => {
              // this.$modal.msgSuccess("新增成功");
              this.$message({
                    message: '数据添加成功',
                    type: 'success'
                })
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // /** 删除按钮操作 */
    // handleDelete(row) {
    //   const ids = row.fileId || this.fileId;
    //   this.$modal.confirm('是否确认删除患者编号为"' + ids + '"的数据项？').then(function() {
    //     return deleteFile(ids);
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // },
    handleDelete(row){
        const ids = row.fileId || this.fileId;
        deleteFile(ids).then(response =>{
             this.$message({
                    message: '数据删除成功',
                    type: 'success'
                })
             
              this.getList();
        })
        
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有劳务付款数据项？').then(() => {
        this.exportLoading = true;
        return exportPayment(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
  
};
</script>

